package org.zhaozhen.order.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zhaozhen.basic.Constant.LoginConstant;
import org.zhaozhen.basic.util.AjaxResult;
import org.zhaozhen.basic.util.LoginContext;
import org.zhaozhen.basic.util.PageList;
import org.zhaozhen.order.domain.AdoptOrder;
import org.zhaozhen.order.query.AdoptOrderQuery;
import org.zhaozhen.order.service.IAdoptOrderService;
import org.zhaozhen.pet.domain.Pet;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;


    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> param, HttpServletRequest request){
        try{
            String payData = adoptOrderService.submit(param, LoginContext.getCurrentLogin(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }
    }
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        PageList<AdoptOrder> adoptOrderPageList = adoptOrderService.queryAdmin(query,LoginContext.getCurrentLogin(request));
        return adoptOrderPageList;
    }

    @GetMapping("/{id}")
    public AdoptOrder queryById(@PathVariable("id") Long id){
        AdoptOrder adoptOrder = adoptOrderService.queryById(id);
        return adoptOrder;
    }

}
